<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <!-- <el-form-item label="">
        <el-select
          filterable
          v-model="queryParams.turnoutType"
          placeholder="道岔种类"
          clearable
          style="width: 140px"
        >
          <el-option
            v-for="dict in turnoutTypearr"
            :key="dict.turnoutType"
            :label="dict.turnoutType"
            :value="dict.turnoutTypeId"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="">
        <el-select
          filterable
          v-model="queryParams.railwayId"
          placeholder="线名"
          clearable
          style="width: 140px"
        >
          <el-option
            v-for="dict in railwayNamearr"
            :key="dict.railwayName"
            :label="dict.railwayName"
            :value="dict.railwayId"
          />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="">
        <el-select
          filterable
          clearable
          style="width: 140px"
          v-model="queryParams.stationId"
          placeholder="车站名"
        >
          <el-option
            v-for="dict in stationNamearr"
            :label="dict.stationName"
            :value="dict.stationId"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="">
        <el-select
          filterable
          v-model="queryParams.railwayModelId"
          placeholder="线别"
          clearable
          style="width: 140px"
        >
          <el-option
            v-for="dict in railwayModelarr"
            :key="dict.railwayModel"
            :label="dict.railwayModel"
            :value="dict.railwayModelId"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="" class="formitemcla">
        <el-input
          v-model="queryParams.turnoutCode"
          placeholder="道岔编号"
          clearable
          style="width: 140px"
        >
        </el-input>
      </el-form-item>
      <!-- <el-form-item label="">
        <el-select
          filterable
          v-model="queryParams.turnoutModelId"
          placeholder="道岔型号"
          clearable
          style="width: 140px"
        >
          <el-option
            v-for="dict in turnoutModelarr"
            :key="dict.turnoutModel"
            :label="dict.turnoutModel"
            :value="dict.turnoutModelId"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="handleQuery" style="width: 90px"
          >查询</el-button
        >
        <el-button @click="resetQuery" style="width: 90px">重置</el-button>
        <el-button type="primary" style="width: 90px" @click="handleExport"
          >导出</el-button
        >
        <el-button type="primary" @click="handleAdd" style="width: 90px"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="turnoutList"
      height="62vh"
      border
      @selection-change="selectiontab"
    >
      <el-table-column type="selection" label="全选" width="50" />
      <!-- <el-table-column label="线名" prop="railwayName" />
      
      <el-table-column label="线别" prop="railwayModel" />
      <el-table-column label="道岔型号" prop="turnoutModel" /> -->
      <el-table-column label="所属车站" prop="stationName" />
      <el-table-column label="道岔种类" prop="turnoutType" />
      <el-table-column label="道岔编号" prop="turnoutCode" />
      <el-table-column label="道岔坐标" prop="mileage" />
      <el-table-column label="尖轨尖端里程" prop="switchMileageNumber" />
      <el-table-column label="左右开" prop="leftRightOpen" />
      <el-table-column label="岔枕类型" prop="switchTieType" />
      <!-- //钢轨单重-- -->
      <el-table-column label="钢轨类型" prop="railType" />
      <el-table-column label="图号" prop="figureNumber" />
      <el-table-column label="侧向通过速度(km/h)" prop="allowPassSpeedSide" />
      <el-table-column label="备注" prop="remark" min-width="80" />
      <!-- <el-table-column label="辙叉号" prop="frogCode" />
      <el-table-column label="辙叉长" prop="frogLength" />
      <el-table-column label="道岔全长" prop="turnoutTotal" />
      <el-table-column label="铺设年度" prop="layingYear" /> -->
      <el-table-column label="直接数据" min-width="110">
        <template #default="scope" class="buttontext">
          <el-button link type="primary" @click="handleUpdate(scope.row)"
            >参数</el-button
          >
          <el-button link type="primary" @click="meansFun(scope.row)"
            >资料</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="关联数据" min-width="210">
        <template #default="scope" class="buttontext">
          <el-button link type="primary" @click="resumeUpdate(scope.row)"
            >作业履历</el-button
          >
          <el-button link type="primary" @click="deviceProblem(scope.row)"
            >设备问题</el-button
          >
          <el-button link type="primary" @click="businessFinance(scope.row)"
            >业财</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="70">
        <template #default="scope" class="buttontext">
          <el-button link type="primary" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      draggable
      title="资料"
      v-model="meansopen"
      width="1300px"
      append-to-body
      @close="closefun"
    >
      <means :forma="formam" parentName="站内道岔" v-if="meansopen"></means>
    </el-dialog>
    <!-- 添加或修改站内设备-道岔信息对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      width="1250px"
      append-to-body
      draggable
    >
      <el-form
        ref="form"
        :model="forma"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">位置</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="单位名称" prop="unitId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.unitId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in unitNameobj"
              :label="dict.unitName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="线名" prop="railwayId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railwayId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railwayNameobj"
              :label="dict.railwayName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车站名" prop="stationId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.stationId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in stationNameobj"
              :label="dict.stationName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="线别" prop="railwayModelId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railwayModelId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railwayModelobj"
              :label="dict.railwayModel"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="道岔编号" prop="turnoutCode">
          <el-input
            style="width: 180px"
            v-model="forma.turnoutCode"
            placeholder="请输入道岔编号"
          />
        </el-form-item>
        <el-form-item label="道岔坐标" prop="mileageNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.mileageNumber"
            placeholder="请输入道岔坐标"
          />
        </el-form-item>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">特性</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="道岔型号" prop="turnoutModelId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.turnoutModelId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in turnoutModelobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="轨距类型" prop="gaugeTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.gaugeTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in gaugeTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="道岔种类" prop="turnoutTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.turnoutTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in turnoutTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交分标记" prop="crossMark">
          <el-input
            style="width: 180px"
            v-model="forma.crossMark"
            placeholder="请输入交分标记"
          />
        </el-form-item>
        <el-form-item label="左右开" prop="leftRightOpenId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.leftRightOpenId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in leftRightOpenobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="图号" prop="figureNumber">
          <el-input
            style="width: 180px"
            v-model="forma.figureNumber"
            placeholder="请输入图号"
          />
        </el-form-item>
        <el-form-item label="整组道岔图号" prop="turnoutFigureNumber">
          <el-input
            style="width: 180px"
            v-model="forma.turnoutFigureNumber"
            placeholder="请输入整组道岔图号"
          />
        </el-form-item>
        <!-- <el-form-item label="钢轨类型" prop="railTypeId">
          <el-select filterable clearable style="width: 180px" v-model="forma.railTypeId" placeholder="请选择">
            <el-option v-for="dict in railTypeobj" :label="dict.propertyName" :value="dict.id"></el-option>
          </el-select>
        </el-form-item> -->
        <!-- 钢轨单重 -->
        <el-form-item label="钢轨类型" prop="railWeightId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railWeightId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railWeightobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="辙叉号" prop="frogCodeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.frogCodeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in frogCodeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="辙叉构造" prop="frogStructureId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.frogStructureId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in frogStructureobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="辙叉长" prop="frogLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.frogLength"
            placeholder="请输入辙叉长"
          />
        </el-form-item>
        <el-form-item label="岔心" prop="turnoutCenter">
          <el-input
            style="width: 180px"
            v-model="forma.turnoutCenter"
            placeholder="请输入岔心"
          />
        </el-form-item>
        <el-form-item label="尖轨类型" prop="switchTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.switchTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in switchTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="左尖轨长" prop="leftSwitchLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.leftSwitchLength"
            placeholder="请输入左尖轨长"
          />
        </el-form-item>
        <el-form-item label="右尖轨长" prop="rightSwitchLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.rightSwitchLength"
            placeholder="请输入右尖轨长"
          />
        </el-form-item>
        <el-form-item label="道岔全长" prop="turnoutTotal">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.turnoutTotal"
            placeholder="请输入道岔全长"
          />
        </el-form-item>
        <el-form-item label="基本轨长度" prop="basicRailLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.basicRailLength"
            placeholder="请输入基本轨长度"
          />
        </el-form-item>
        <el-form-item label="扳道器种类" prop="switchgearTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.switchgearTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in switchgearTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联锁类别" prop="interlockTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.interlockTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in interlockTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岔枕类型" prop="switchTieTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.switchTieTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in switchTieTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岔枕数量" prop="switchTieNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.switchTieNumber"
            placeholder="请输入岔枕数量"
          />
        </el-form-item>
        <el-form-item label="岔枕体积" prop="switchTieVolume">
          <el-input
            style="width: 180px"
            v-model="forma.switchTieVolume"
            placeholder="请输入岔枕体积"
          />
        </el-form-item>
        <el-form-item label="尖轨尖端里程" prop="switchMileageNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.switchMileageNumber"
            placeholder="请输入尖轨尖端里程"
          />
        </el-form-item>
        <el-form-item label="尖轨长度" prop="switchLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.switchLength"
            placeholder="请输入尖轨长度"
          />
        </el-form-item>
        <el-form-item label="直向速度" prop="frontSpeed">
          <el-input
            style="width: 180px"
            v-model="forma.frontSpeed"
            placeholder="请输入直向速度"
          />
        </el-form-item>
        <el-form-item label="侧向速度" prop="sideSpeed">
          <el-input
            style="width: 180px"
            v-model="forma.sideSpeed"
            placeholder="请输入侧向速度"
          />
        </el-form-item>
        <el-form-item label="铺设年度" prop="layingYear">
          <el-date-picker
            style="width: 180px"
            format="YYYY/MM/DD"
            value-format="YYYY/MM/DD"
            v-model="forma.layingYear"
            type="datetime"
            placeholder="请输入铺设年度"
          />
        </el-form-item>
        <el-form-item label="岔前轨长" prop="turnoutBeforeLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.turnoutBeforeLength"
            placeholder="请输入岔前轨长"
          />
        </el-form-item>
        <el-form-item label="岔后轨长" prop="turnoutAfterLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.turnoutAfterLength"
            placeholder="请输入岔后轨长"
          />
        </el-form-item>
        <el-form-item label="岔尾里程" prop="turnoutEndMileageNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.turnoutEndMileageNumber"
            placeholder="请输入岔尾里程"
          />
        </el-form-item>
        <el-form-item label="尖轨朝向" prop="switchDirectionId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.switchDirectionId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in switchDirectionobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="锁闭形式" prop="lockingShapeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.lockingShapeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in lockingShapeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="扣件类型" prop="fastenTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.fastenTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in fastenTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交叉类型" prop="crossTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.crossTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in crossTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="组合类型" prop="combinationTypeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.combinationTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in combinationTypeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="轨件长度" prop="railLength">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.railLength"
            placeholder="请输入轨件长度"
          />
        </el-form-item>
        <el-form-item label="轨件形式" prop="railShapeId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railShapeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railShapeobj"
              :label="dict.propertyName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="轨件生产厂家" prop="railManufacturer">
          <el-input
            style="width: 180px"
            v-model="forma.railManufacturer"
            placeholder="请输入轨件生产厂家"
          />
        </el-form-item>
        <el-form-item label="轨件上道日期" prop="inRailDate">
          <el-date-picker
            style="width: 180px"
            format="YYYY/MM/DD"
            value-format="YYYY/MM/DD"
            v-model="forma.inRailDate"
            type="datetime"
            placeholder="请输入轨件上道日期"
          />
        </el-form-item>
        <el-form-item label="轨件ERP编码" prop="railErpCode">
          <el-input
            style="width: 180px"
            v-model="forma.railErpCode"
            placeholder="请输入轨件ERP编码"
          />
        </el-form-item>
        <el-form-item label="容许通过速度-V直" prop="allowPassSpeedFront">
          <el-input
            style="width: 180px"
            v-model="forma.allowPassSpeedFront"
            placeholder="请输入容许通过速度-V直"
          />
        </el-form-item>
        <el-form-item label="侧向通过速度(km/h)" prop="allowPassSpeedSide">
          <el-input
            style="width: 180px"
            v-model="forma.allowPassSpeedSide"
            placeholder="请输入侧向通过速度(km/h)"
          />
        </el-form-item>
        <el-form-item label="金属件总重" prop="metalPartsHeight">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.metalPartsHeight"
            placeholder="请输入金属件总重"
          />
        </el-form-item>
        <el-form-item label="底面高程" prop="bottomHeight">
          <el-input
            style="width: 180px"
            v-model="forma.bottomHeight"
            placeholder="请输入底面高程"
          />
        </el-form-item>
        <el-form-item label="道岔生产厂家" prop="turnoutManufacturer">
          <el-input
            style="width: 180px"
            v-model="forma.turnoutManufacturer"
            placeholder="请输入道岔生产厂家"
          />
        </el-form-item>
        <el-form-item label="铺设单位" prop="layingUnit">
          <el-input
            style="width: 180px"
            v-model="forma.layingUnit"
            placeholder="请输入铺设单位"
          />
        </el-form-item>
        <el-form-item label="通过总重" prop="passWeight">
          <el-input
            style="width: 180px"
            v-model="forma.passWeight"
            placeholder="请输入通过总重"
          />
        </el-form-item>
        <el-form-item label="转辙次数" prop="switchNumber">
          <el-input
            style="width: 180px"
            v-model="forma.switchNumber"
            placeholder="请输入转辙次数"
          />
        </el-form-item>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">健康度</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="健康值" prop="healthIndex">
          <el-input
            style="width: 180px"
            v-model="forma.healthIndex"
            placeholder="请输入健康值"
          />
        </el-form-item>
        <el-form-item label="隐患等级" prop="hiddenDangerLevel">
          <el-input
            style="width: 180px"
            v-model="forma.hiddenDangerLevel"
            placeholder="请输入隐患等级"
          />
        </el-form-item>
        <el-form-item label="设备使用频率" prop="equipmentUsageFrequency">
          <el-input
            style="width: 180px"
            v-model="forma.equipmentUsageFrequency"
            placeholder="请输入设备使用频率"
          />
        </el-form-item>
        <el-form-item label="设备综合效率(OEE)" prop="oee">
          <el-input
            style="width: 180px"
            v-model="forma.oee"
            placeholder="请输入设备综合效率(OEE)"
          />
        </el-form-item>
        <el-form-item label="平均无故障工作时间(MTBF)" prop="mtbf">
          <el-input
            style="width: 180px"
            v-model="forma.mtbf"
            placeholder="请输入平均无故障工作时间(MTBF)"
          />
        </el-form-item>
        <el-form-item label="平均修复时间(MTTR)" prop="mttr">
          <el-input
            style="width: 180px"
            v-model="forma.mttr"
            placeholder="请输入平均修复时间(MTTR)"
          />
        </el-form-item>
        <div class="divflex">
          <span class="leftx"></span>
          <span class="mainz">管理</span>
          <span class="rightx"></span>
        </div>
        <el-form-item label="区段" prop="zone">
          <el-input
            style="width: 180px"
            v-model="forma.zone"
            placeholder="请输入区段"
          />
        </el-form-item>
        <el-form-item label="工区" prop="workArea">
          <el-input
            style="width: 180px"
            v-model="forma.workArea"
            placeholder="请输入工区"
          />
        </el-form-item>
        <el-form-item label="人员" prop="user">
          <el-input
            style="width: 180px"
            v-model="forma.user"
            placeholder="请输入人员"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="forma.remark"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 4 }"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="divflex" v-if="title == '道岔信息修改'">
        <span class="leftx"></span>
        <span class="mainz">修改历史</span>
        <span class="rightx"></span>
      </div>
      <el-table
        v-if="title == '道岔信息修改'"
        :data="historyList"
        height="20vh"
        border
      >
        <el-table-column
          label="序号"
          type="index"
          min-width="80"
        ></el-table-column>
        <el-table-column
          label="指标名"
          prop="property"
          min-width="80"
        ></el-table-column>
        <el-table-column label="变更前指标值" prop="oldValue" min-width="110">
        </el-table-column>
        <el-table-column label="变更后指标值" prop="newValue" min-width="80">
        </el-table-column>
        <el-table-column label="变更时间" prop="createTime" min-width="80">
        </el-table-column>
        <el-table-column label="操作用户名" prop="user" min-width="80">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="subgrade">
import {
  insertManStationFacilityTurnoutapi,
  selectManStationFacilityTurnoutListapi,
  editManStationFacilityTurnoutapi,
  deleteManStationFacilityTurnoutByIdapi,
  selectManBasicRailwayListapi,
  selectManBasicUnitListapi,
  selectManBasicRailwayModelListapi,
  selectManBasicPropertyListapi,
  selectManBasicStationListapi,
  selectManRailEditRecordListapi,
} from "@/api/main/api.js";
import { useContent } from "@/mixin/index.js";
const {
  meansopen,
  meansFun,
  formam,
  closefun,
  resumeUpdate,
  deviceProblem,
  businessFinance,
} = useContent();
import means from "@/components/railmodle/means.vue";
defineExpose({ getList });
const emit = defineEmits(["parentCount"]);
import { reactive, ref, toRefs } from "vue";
const { proxy } = getCurrentInstance();
const loading = ref(true);
const title = ref("道岔信息新增");
const open = ref(false);
const data = reactive({
  // 基础数据-单位数据表格数据
  turnoutList: [],
  // 查询参数
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    railwayName: "",
    railwayModel: "",
    turnoutCode: "",
    turnoutModel: "",
    railwayId: "",
    railwayModelId: "",
    stationName: "",
    stationId: "",
    turnoutModelId: "",
    turnoutType: "",
  },
  railwayModelobj: [],
  railwayNameobj: [],
  unitNameobj: [],
  // 表单参数
  forma: {},
  // 表单校验
  rules: {
    unitId: [
      {
        required: true,
        message: "单位名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    railwayId: [
      {
        required: true,
        message: "线路名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    railwayModelId: [
      { required: true, message: "线别不能为空", trigger: ["blur", "change"] },
    ],
    stationId: [
      {
        required: true,
        message: "车站名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    mileageNumber: [
      {
        required: true,
        message: "道岔坐标不能为空",
        trigger: ["blur", "change"],
      },
    ],
    turnoutCode: [
      {
        required: true,
        message: "道岔编号不能为空",
        trigger: ["blur", "change"],
      },
    ],
    turnoutTypeId: [
      {
        required: true,
        message: "道岔种类不能为空",
        trigger: ["blur", "change"],
      },
    ],
    leftRightOpenId: [
      {
        required: true,
        message: "左右开不能为空",
        trigger: ["blur", "change"],
      },
    ],
    railWeightId: [
      {
        required: true,
        message: "钢轨类型不能为空",
        trigger: ["blur", "change"],
      },
    ],
    // frogCodeId: [
    //   {
    //     required: true,
    //     message: "辙叉号不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    // frogStructureId: [
    //   {
    //     required: true,
    //     message: "辙叉构造不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    // switchTypeId: [
    //   {
    //     required: true,
    //     message: "尖轨类型不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    // turnoutTotal: [
    //   {
    //     required: true,
    //     message: "道岔全长不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    switchMileageNumber: [
      {
        required: true,
        message: "尖轨尖端里程不能为空",
        trigger: ["blur", "change"],
      },
    ],
    // layingYear: [
    //   {
    //     required: true,
    //     message: "铺设年度不能为空",
    //     trigger: ["blur", "change"],
    //   },
    // ],
  },
  editobj: {},
  railwayNamearr: [],
  propertyList: [],
  turnoutModelobj: [],
  turnoutTypeobj: [],
  leftRightOpenobj: [],
  railWeightobj: [],
  frogCodeobj: [],
  gaugeTypeobj: [],
  railTypeobj: [],
  frogStructureobj: [],
  switchTypeobj: [],
  switchgearTypeobj: [],
  interlockTypeobj: [],
  switchTieTypeobj: [],
  switchDirectionobj: [],
  lockingShapeobj: [],
  fastenTypeobj: [],
  crossTypeobj: [],
  combinationTypeobj: [],
  railShapeobj: [],
  stationNameobj: [],
  stationNamearr: [],
  railwayModelarr: [],
  turnoutModelarr: [],
  historyList: [],
  selecttabList: [],
  turnoutTypearr: [],
});
const {
  turnoutTypearr,
  selecttabList,
  historyList,
  turnoutModelarr,
  railwayModelarr,
  stationNamearr,
  stationNameobj,
  railWeightobj,
  frogCodeobj,
  gaugeTypeobj,
  railTypeobj,
  frogStructureobj,
  switchTypeobj,
  switchgearTypeobj,
  interlockTypeobj,
  switchTieTypeobj,
  switchDirectionobj,
  lockingShapeobj,
  fastenTypeobj,
  crossTypeobj,
  combinationTypeobj,
  railShapeobj,
  leftRightOpenobj,
  turnoutTypeobj,
  turnoutModelobj,
  propertyList,
  railwayNamearr,
  queryParams,
  forma,
  rules,
  turnoutList,
  unitNameobj,
  railwayNameobj,
  editobj,
  railwayModelobj,
} = toRefs(data);
//修改记录查询
function historyListfun() {
  selectManRailEditRecordListapi({ equipmentId: editobj.value.id }).then(
    (res) => {
      historyList.value = res.data;
    }
  );
}
function selectiontab(row) {
  selecttabList.value = row;
}
/** 导出按钮操作 */
function handleExport() {
  if (selecttabList.value.length == 0) {
    proxy.$modal.msgError("请选择设备");
    return;
  }
  const arrid = [];
  for (let i = 0; i < selecttabList.value.length; i++) {
    arrid.push(selecttabList.value[i].id);
  }
  proxy.download1(
    "facility-manage/stationFacilityTurnout/exportExcel",
    arrid,
    `站内道岔${new Date().getTime()}.xlsx`
  );
}
/** 查询基础数据-道岔数据列表 */
const pageNumparent = ref(undefined);
const pageSizeparent = ref(undefined);
/** 查询列表 */
function getList(pageNum, pageSize) {
  loading.value = true;
  if (pageNum != undefined || pageSize != undefined) {
    pageNumparent.value = pageNum;
    pageSizeparent.value = pageSize;
    queryParams.value.pageNum = pageNum == undefined ? 1 : pageNum;
    queryParams.value.pageSize = pageSize == undefined ? 10 : pageSize;
  } else {
    queryParams.value.pageNum =
      pageNumparent.value == undefined ? "1" : pageNumparent.value;
    queryParams.value.pageSize =
      pageSizeparent.value == undefined ? "10" : pageSizeparent.value;
  }
  selectManStationFacilityTurnoutListapi(queryParams.value).then((res) => {
    if (res.code == 200) {
      turnoutList.value = res.data;
      loading.value = false;
      const mingc = {};
      railwayNamearr.value = turnoutList.value.reduce((next, item) => {
        mingc[item.railwayName] == undefined
          ? (mingc[item.railwayName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const che = {};
      turnoutModelarr.value = turnoutList.value.reduce((next, item) => {
        che[item.turnoutModel] == undefined
          ? (che[item.turnoutModel] = true & next.push(item))
          : "";
        return next;
      }, []);
      const xian = {};
      railwayModelarr.value = turnoutList.value.reduce((next, item) => {
        xian[item.railwayModel] == undefined
          ? (xian[item.railwayModel] = true & next.push(item))
          : "";
        return next;
      }, []);
      const daoc = {};
      stationNamearr.value = turnoutList.value.reduce((next, item) => {
        daoc[item.stationName] == undefined
          ? (daoc[item.stationName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const dczl = {};
      turnoutTypearr.value = turnoutList.value.reduce((next, item) => {
        dczl[item.turnoutType] == undefined
          ? (dczl[item.turnoutType] = true & next.push(item))
          : "";
        return next;
      }, []);
      emit("parentCount", res.count);
    }
  });
}
getList();

/** 查询基础数据-线名数据列表 */
function getList1() {
  selectManBasicRailwayListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
    }
  });
}
getList1();
/** 查询基础数据-单位数据列表 */
function getList2() {
  selectManBasicUnitListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      unitNameobj.value = res.data;
    }
  });
}
getList2();
/** 查询基础数据-线别数据列表 */
function getList3() {
  selectManBasicRailwayModelListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayModelobj.value = res.data;
    }
  });
}
getList3();

/** 查询基础数据-车站数据列表 */
function getList5() {
  selectManBasicStationListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      stationNameobj.value = res.data;
    }
  });
}
getList5();

/** 查询基础数据-属性维护数据列表 */
function getList4() {
  selectManBasicPropertyListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      propertyList.value = res.data;
      railWeightobj.value = [];
      frogCodeobj.value = [];
      gaugeTypeobj.value = [];
      railTypeobj.value = [];
      frogStructureobj.value = [];
      switchTypeobj.value = [];
      switchgearTypeobj.value = [];
      interlockTypeobj.value = [];
      switchTieTypeobj.value = [];
      switchDirectionobj.value = [];
      lockingShapeobj.value = [];
      fastenTypeobj.value = [];
      crossTypeobj.value = [];
      combinationTypeobj.value = [];
      railShapeobj.value = [];
      leftRightOpenobj.value = [];
      turnoutTypeobj.value = [];
      turnoutModelobj.value = [];
      for (let i = 0; i < propertyList.value.length; i++) {
        if (propertyList.value[i].propertyType == "钢轨单重") {
          railWeightobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "辙叉号") {
          frogCodeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "轨距类型") {
          gaugeTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "钢轨类型") {
          railTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "辙叉构造") {
          frogStructureobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "尖轨类型") {
          switchTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "扳道器种类") {
          switchgearTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "联锁类别") {
          interlockTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "岔枕类型") {
          switchTieTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "尖轨朝向") {
          switchDirectionobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "锁闭形式") {
          lockingShapeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "扣件类型") {
          fastenTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "交叉类型") {
          crossTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "组合类型") {
          combinationTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "轨件形式") {
          railShapeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "左右开") {
          leftRightOpenobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "道岔种类") {
          turnoutTypeobj.value.push(propertyList.value[i]);
        }
        if (propertyList.value[i].propertyType == "道岔型号") {
          turnoutModelobj.value.push(propertyList.value[i]);
        }
      }
    }
  });
}
getList4();
// 取消按钮
function cancel() {
  open.value = false;
}
/** 搜索按钮操作 */
function handleQuery() {
  getList();
}
//重置
function resetQuery() {
  queryParams.value = {
    railwayName: "",
    railwayModel: "",
    turnoutCode: "",
    turnoutModel: "",
    railwayId: "",
    railwayModelId: "",
    stationName: "",
    stationId: "",
    turnoutModelId: "",
    turnoutType: "",
  };
  getList();
}
function clear() {
  forma.value = {
    unitName: "",
    railwayName: "",
    stationName: "",
    railwayModel: "",
    turnoutModel: "",
    turnoutType: "",
    leftRightOpen: "",
    railWeight: "",
    frogCode: "",
    gaugeType: "",
    railType: "",
    frogStructure: "",
    switchType: "",
    switchgearType: "",
    interlockType: "",
    switchTieType: "",
    switchDirection: "",
    lockingShape: "",
    fastenType: "",
    crossType: "",
    combinationType: "",
    railShape: "",
    unitId: "",
    railwayId: "",
    stationId: "",
    railwayModelId: "",
    turnoutCode: "",
    mileage: "",
    mileageNumber: "",
    turnoutModelId: "",
    gaugeTypeId: "",
    turnoutTypeId: "",
    crossMark: "",
    leftRightOpenId: "",
    figureNumber: "",
    turnoutFigureNumber: "",
    railTypeId: "",
    railWeightId: "",
    frogCodeId: "",
    frogStructureId: "",
    frogLength: "",
    turnoutCenter: "",
    switchTypeId: "",
    leftSwitchLength: "",
    rightSwitchLength: "",
    turnoutTotal: "",
    basicRailLength: "",
    switchgearTypeId: "",
    interlockTypeId: "",
    switchTieTypeId: "",
    switchTieNumber: "",
    switchTieVolume: "",
    switchMileage: "",
    switchMileageNumber: "",
    switchLength: "",
    frontSpeed: "",
    sideSpeed: "",
    layingYear: "",
    turnoutBeforeLength: "",
    turnoutAfterLength: "",
    turnoutEndMileage: "",
    turnoutEndMileageNumber: "",
    switchDirectionId: "",
    lockingShapeId: "",
    fastenTypeId: "",
    crossTypeId: "",
    combinationTypeId: "",
    railLength: "",
    railShapeId: "",
    railManufacturer: "",
    inRailDate: "",
    railErpCode: "",
    allowPassSpeedFront: "",
    allowPassSpeedSide: "",
    metalPartsHeight: "",
    bottomHeight: "",
    turnoutManufacturer: "",
    layingUnit: "",
    passWeight: "",
    switchNumber: "",
    healthIndex: "",
    hiddenDangerLevel: "",
    equipmentUsageFrequency: "",
    oee: "",
    mtbf: "",
    mttr: "",
    zone: "",
    workArea: "",
    user: "",
    hasDelete: "",
  };
}
/** 新增按钮操作 */
function handleAdd() {
  open.value = true;
  clear();
  title.value = "道岔信息新增";
}
/** 修改按钮操作 */
function handleUpdate(row) {
  title.value = "道岔信息修改";
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  historyListfun();
  open.value = true;
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm("是否确认删除")
    .then(function () {
      return deleteManStationFacilityTurnoutByIdapi({ id: row.id });
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      if (forma.value.id != null) {
        const newforma = JSON.parse(JSON.stringify(forma.value));
        for (const key in editobj.value) {
          for (const keya in newforma) {
            if (
              key == keya &&
              editobj.value[key] == newforma[keya] &&
              key != "id"
            ) {
              Reflect.deleteProperty(newforma, keya);
            }
          }
        }
        if (
          newforma.mileageNumber != undefined &&
          newforma.mileageNumber != null
        ) {
          newforma.mileageNumber =
            Math.round(newforma.mileageNumber * 1000000) / 1000000;
        }
        if (
          newforma.switchMileageNumber != undefined &&
          newforma.switchMileageNumber != null &&
          newforma.switchMileageNumber != ""
        ) {
          newforma.switchMileageNumber =
            Math.round(newforma.switchMileageNumber * 1000000) / 1000000;
        }
        if (
          newforma.turnoutEndMileageNumber != undefined &&
          newforma.turnoutEndMileageNumber != null &&
          newforma.turnoutEndMileageNumber != ""
        ) {
          newforma.turnoutEndMileageNumber =
            Math.round(newforma.turnoutEndMileageNumber * 1000000) / 1000000;
        }
        if (Object.keys(newforma).length <= 1) {
          open.value = false;
        } else {
          editManStationFacilityTurnoutapi(newforma).then((res) => {
            proxy.$modal.msgSuccess("修改成功");
            open.value = false;
            getList();
          });
        }
      } else {
        if (
          forma.value.switchMileageNumber != undefined &&
          forma.value.switchMileageNumber != null &&
          forma.value.switchMileageNumber != ""
        ) {
          forma.value.switchMileageNumber =
            Math.round(forma.value.switchMileageNumber * 1000000) / 1000000;
        }
        if (
          forma.value.turnoutEndMileageNumber != undefined &&
          forma.value.turnoutEndMileageNumber != null &&
          forma.value.turnoutEndMileageNumber != ""
        ) {
          forma.value.turnoutEndMileageNumber =
            Math.round(forma.value.turnoutEndMileageNumber * 1000000) / 1000000;
        }
        forma.value.mileageNumber =
          Math.round(forma.value.mileageNumber * 1000000) / 1000000;
        insertManStationFacilityTurnoutapi(forma.value).then((res) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
</script>
